package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.EquipRepairSpareInfo;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.EquipRepairSpareInfoService;

@Controller
@RequestMapping("/equipRepairSpareInfo")
public class EquipRepairSpareInfoController {
	
	
	@Autowired
	private EquipRepairSpareInfoService equipRepairSpareInfoService;
	
	@RequestMapping(value = "/operateByEquipRepairSpareInfo")
	public @ResponseBody ResultBean operateByEquipRepairSpareInfo(@RequestBody EquipRepairSpareInfo equipRepairSpareInfo) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (equipRepairSpareInfo.getModificationFlag() == IModificationFlags.NEW) {
			return equipRepairSpareInfoService.save(equipRepairSpareInfo);
			// Judge to update
		} else if (equipRepairSpareInfo.getModificationFlag() == IModificationFlags.MODIFIED) {
			return equipRepairSpareInfoService.update(equipRepairSpareInfo);
			// Judge to delete
		} else if (equipRepairSpareInfo.getModificationFlag() == IModificationFlags.DELETED) {
			return equipRepairSpareInfoService.delete(equipRepairSpareInfo);
		}
		return resultBean;
	}
	
	@RequestMapping(value = "getByRepairInfoId/{repairInfoId}")
	public @ResponseBody ResultBean getByRepairInfoId(@PathVariable long repairInfoId) {
		return equipRepairSpareInfoService.getByRepairInfoId(repairInfoId);
	}
	

}
